package org.hwadee.mapper;

import org.apache.ibatis.annotations.*;
import org.hwadee.entity.Interest;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface InterestMapper {

    // 获取粉丝列表
    @Select("select interestId,follower as followerid,followed as followedid from interest where followed = #{userId}")
    List<Interest> getAllFollower(Integer userId);

    // 获取关注列表
    @Select("select interestId,follower as followerid,followed as followedid from interest where follower = #{userId}")
    List<Interest> getAllFollowed(Integer userId);

    // 增加
    @Insert("insert into interest(follower, followed) values (#{followerId}, #{followedId})")
    void insertInterest(Interest interest);

    @Select("select count(*) from interest where follower=#{followerId} and followed=#{followedId}")
    int checkInterest(@Param("followerId") Integer followerId, @Param("followedId") Integer followedId);

    @Delete("delete from interest where follower = #{followerId} and followed = #{followedId}")
    void deleteInterest(Interest interest);

//    @Update("update interest set followerCount + 1 where interestId = #{interestId}")
//    void addFollowerCount(Integer interestId);
//
//    @Update("update interest set followedCount + 1 where interestId = #{interestId}")
//    void addFollowedCount(Integer interestId);
//
//    @Update("update interest set followerCount - 1 where interestId = #{interestId}")
//    void reduceFollowerCount(Integer interestId);
//
//    @Update("update interest set followedCount - 1 where interestId = #{interestId}")
//    void reduceFollowedCount(Integer interestId);

    //@Select("select * from interest where interestId = #{interestId}")
    //Interest getFollower(Integer interestId);

    //@Select("select * from interest where interestId = #{interestId}")
    //Interest getFollowed(Integer interestId);
}
